#pragma once

//
// Collects command line arguements and sets up the program execution states.  The parser for NMAPI
// is loaded here.  The capture file is also opened.  The capture engine is initialized and 
// started/stopped with this class.
//
class CPrgExeState
{
public:
	//
	// Initializes the class by collecting all the command line arguments and saving
	// them in class variables.
	//
	CPrgExeState(int argc, WCHAR* argv[]);
	~CPrgExeState(void);

	void PrintHelp();

	bool IsNPLErrors(){ return (ErrorLoadingNPL); };
	bool IsValidCommandLine() { return _IsValidCommandLine; };
	//
	// Creates a frame parser and m_Filter if a m_Filter is specified.  Also disables
	// conversations if that option is presented.  User can shot themselvs in the
	// foot if a m_Filter requires converations and they disalble them.
	//
	void LoadNPL(void);
	void UnLoadNPL(void);
	// 
	// Callback for building the NPL.  This is only needed if a m_Filter is used.
	// Only errors will be printed out, unless m_Verbose mode is specified.
	//
	void static __stdcall MyParserBuild(PVOID Context, ULONG StatusCode, LPCWSTR lpDescription, ULONG ErrorType);
	//
	// Checks to see if the capture file is there if the option to overwrite capture
	// is not specified.  Creates the capture file based on the options present for
	// size and wrap vs. chained.
	//
	bool CreateCap(void);
	//
	// Initializes the capture engine and configures all adapters specified.
	//
	bool InitCapture(void);
	//
	// Callback for each frame indicated.  If a m_Filter is provided, it checks that the frame
	// passes before storing in the frame.
	//
	void static __stdcall MyFrameIndication(HANDLE hCapEng, ULONG ulAdaptIdx, PVOID pContext, HANDLE hRawFrame);
	// 
	// Starts capture on all adapters specified.
	//
	bool StartCapture(void);
	// 
	// Stops capture on all adapters specified.
	//
	bool StopCapture(void);
	//
	// Checks to see if a rawFrame passes a m_Filter.
	//
	BOOL PassFilter(HANDLE rawFrame);

public:
	DWORD m_LastError;
	WCHAR *m_Filter;
	WCHAR *m_CapFile;
	WCHAR *m_EventNum;
	WCHAR *m_LogFile;
	HANDLE m_myCapFile;
	bool m_Verbose;

private:
	WCHAR *AppName;

	ULONG CapFileSize;
	bool ChainCapture;
	ULONG FilterID;

	HANDLE myNplParser;
	HANDLE myFrameParserConfig;
	HANDLE myFrameParser;
	HANDLE myCaptureEngine;
	bool ErrorLoadingNPL;

	bool _IsValidCommandLine;
	ULONG AdpCount;

	bool OverwriteCapture;

	int AdapterNumber;

	bool DisableConv;
};
